# Link flags to pull in dependencies
BINS = cargo \
- cargo-compile \
+ cargo-build \
cargo-read-manifest \
cargo-rustc \
cargo-verify-project \
--- /dev/null
+#![crate_id="cargo-build"]
+#![feature(phase)]
+
+extern crate cargo;
+
+#[phase(plugin, link)]
+extern crate hammer;
+
+#[phase(plugin, link)]
+extern crate log;
+
+extern crate serialize;
+
+use std::os;
+use cargo::{execute_main_without_stdin};
+use cargo::ops;
+use cargo::core::MultiShell;
+use cargo::util::{CliResult, CliError};
+use cargo::util::important_paths::find_project;
+
+#[deriving(PartialEq,Clone,Decodable,Encodable)]
+pub struct Options {
+ manifest_path: Option<String>,
+ update_remotes: bool
+}
+
+hammer_config!(Options "Build the current project", |c| {
+ c.short("update_remotes", 'u')
+})
+
+fn main() {
+ execute_main_without_stdin(execute);
+}
+
+fn execute(options: Options, shell: &mut MultiShell) -> CliResult<Option<()>> {
+ debug!("executing; cmd=cargo-compile; args={}", os::args());
+
+ let root = match options.manifest_path {
+ Some(path) => Path::new(path),
+ None => try!(find_project(os::getcwd(), "Cargo.toml")
+ .map(|path| path.join("Cargo.toml"))
+ .map_err(|_| {
+ CliError::new("Could not find Cargo.toml in this \
+ directory or any parent directory",
+ 102)
+ }))
+ };
+
+ let update = options.update_remotes;
+
+ ops::compile(&root, update, shell).map(|_| None).map_err(|err| {
+ CliError::from_boxed(err, 101)
+ })
+}
+++ /dev/null
-#![crate_id="cargo-compile"]
-#![feature(phase)]
-
-extern crate cargo;
-
-#[phase(plugin, link)]
-extern crate hammer;
-
-#[phase(plugin, link)]
-extern crate log;
-
-extern crate serialize;
-
-use std::os;
-use cargo::{execute_main_without_stdin};
-use cargo::ops;
-use cargo::core::MultiShell;
-use cargo::util::{CliResult, CliError};
-use cargo::util::important_paths::find_project;
-
-#[deriving(PartialEq,Clone,Decodable,Encodable)]
-pub struct Options {
- manifest_path: Option<String>,
- update_remotes: bool
-}
-
-hammer_config!(Options "Compile the current project", |c| {
- c.short("update_remotes", 'u')
-})
-
-fn main() {
- execute_main_without_stdin(execute);
-}
-
-fn execute(options: Options, shell: &mut MultiShell) -> CliResult<Option<()>> {
- debug!("executing; cmd=cargo-compile; args={}", os::args());
-
- let root = match options.manifest_path {
- Some(path) => Path::new(path),
- None => try!(find_project(os::getcwd(), "Cargo.toml")
- .map(|path| path.join("Cargo.toml"))
- .map_err(|_| {
- CliError::new("Could not find Cargo.toml in this \
- directory or any parent directory",
- 102)
- }))
- };
-
- let update = options.update_remotes;
-
- ops::compile(&root, update, shell).map(|_| None).map_err(|err| {
- CliError::from_boxed(err, 101)
- })
-}
fn execute() {
debug!("executing; cmd=cargo; args={}", os::args());
- let (cmd, args) = match process(os::args()) {
- Ok((cmd, args)) => (cmd, args),
- Err(err) => return handle_error(err, &mut shell(false))
- };
+ let (cmd, args) = process(os::args());
match cmd.as_slice() {
"config-for-key" => {
},
"--help" | "-h" | "help" | "-?" => {
println!("Commands:");
- println!(" compile # compile the current project\n");
+ println!(" build # compile the current project\n");
let (_, options) = hammer::usage::<GlobalFlags>(false);
println!("Options (for all commands):\n\n{}", options);
}
}
-fn process(args: Vec<String>) -> CliResult<(String, Vec<String>)> {
- let args: Vec<String> = Vec::from_slice(args.tail());
- let head = try!(args.iter().nth(0).require(|| {
- human("No subcommand found")
- }).map_err(|err| CliError::from_boxed(err, 1))).to_str();
- let tail = Vec::from_slice(args.tail());
+fn process(args: Vec<String>) -> (String, Vec<String>) {
+ let mut args = Vec::from_slice(args.tail());
+ let head = args.shift().unwrap_or("--help".to_str());
- Ok((head, tail))
+ (head, args)
}
#[deriving(Encodable)]
use std::io::{File, IoError};
use std::str;
-use core::{MultiShell, Package, PackageSet, Target};
+use core::{Package, PackageSet, Target};
use util;
use util::{CargoResult, ChainError, ProcessBuilder, internal, human, CargoError};
use util::{Config};
.file("Cargo.toml", basic_bin_manifest("foo").as_slice())
.file("src/foo.rs", main_file(r#""i am foo""#, []).as_slice());
- assert_that(p.cargo_process("cargo-compile"), execs());
+ assert_that(p.cargo_process("cargo-build"), execs());
assert_that(&p.root().join("target/foo"), existing_file());
let target = p.root().join("target");
let p = project("foo")
.file("Cargo.toml", "");
- assert_that(p.cargo_process("cargo-compile"),
+ assert_that(p.cargo_process("cargo-build"),
execs()
.with_status(101)
.with_stderr("Cargo.toml is not a valid manifest\n\n\
foo = bar
");
- assert_that(p.cargo_process("cargo-compile"),
+ assert_that(p.cargo_process("cargo-build"),
execs()
.with_status(101)
.with_stderr("could not parse input TOML\n\
test!(cargo_compile_without_manifest {
let p = project("foo");
- assert_that(p.cargo_process("cargo-compile"),
+ assert_that(p.cargo_process("cargo-build"),
execs()
.with_status(102)
.with_stderr("Could not find Cargo.toml in this directory or any \
let target = realpath(&p.root().join("target")).assert();
- assert_that(p.cargo_process("cargo-compile"),
+ assert_that(p.cargo_process("cargo-build"),
execs()
.with_status(101)
.with_stderr(format!("\
.file("Cargo.toml", basic_bin_manifest("foo").as_slice())
.file("src/foo.rs", "fn main() {} fn dead() {}");
- assert_that(p.cargo_process("cargo-compile"),
+ assert_that(p.cargo_process("cargo-build"),
execs()
.with_stderr("\
src/foo.rs:1:14: 1:26 warning: code is never used: `dead`, #[warn(dead_code)] \
let bar = realpath(&p.root().join("bar")).assert();
let main = realpath(&p.root()).assert();
- assert_that(p.cargo_process("cargo-compile"),
+ assert_that(p.cargo_process("cargo-build"),
execs()
.with_stdout(format!("{} bar v0.5.0 (file:{})\n\
{} foo v0.5.0 (file:{})\n",
}
"#);
- p.cargo_process("cargo-compile")
+ p.cargo_process("cargo-build")
.exec_with_output()
.assert();
}
"#);
- assert_that(p.cargo_process("cargo-compile"), execs());
+ assert_that(p.cargo_process("cargo-build"), execs());
assert_that(&p.root().join("target/foo"), existing_file());
.file("src/foo.rs", r#"
fn main() { println!("Hello!"); }
"#);
- assert_that(build.cargo_process("cargo-compile"),
+ assert_that(build.cargo_process("cargo-build"),
execs().with_status(0));
.file("src/foo.rs", r#"
fn main() {}
"#);
- assert_that(p.cargo_process("cargo-compile"),
+ assert_that(p.cargo_process("cargo-build"),
execs().with_status(0)
.with_stdout(format!(" Compiling foo v0.5.0 (file:{})\n",
p.root().display()))
.file("src/foo.rs", r#"
fn main() { fail!("nope") }
"#);
- assert_that(build.cargo_process("cargo-compile"), execs().with_status(0));
+ assert_that(build.cargo_process("cargo-build"), execs().with_status(0));
let mut p = project("foo");
.file("src/foo.rs", r#"
fn main() {}
"#);
- assert_that(p.cargo_process("cargo-compile"),
+ assert_that(p.cargo_process("cargo-build"),
execs().with_status(101).with_stderr(format!("\
Could not execute process `{}` (status=101)
--- stderr
"#,
p.root().join("target").display(),
p.root().join("target/deps").display()));
- assert_that(build.cargo_process("cargo-compile"), execs().with_status(0));
+ assert_that(build.cargo_process("cargo-build"), execs().with_status(0));
p = p
.file("src/foo.rs", r#"
fn main() {}
"#);
- assert_that(p.cargo_process("cargo-compile"), execs().with_status(0));
+ assert_that(p.cargo_process("cargo-build"), execs().with_status(0));
})
test!(custom_build_in_dependency {
"#,
p.root().join("target/deps").display(),
p.root().join("target/deps").display()));
- assert_that(build.cargo_process("cargo-compile"), execs().with_status(0));
+ assert_that(build.cargo_process("cargo-build"), execs().with_status(0));
p = p
.file("bar/src/bar.rs", r#"
pub fn bar() {}
"#);
- assert_that(p.cargo_process("cargo-compile"),
+ assert_that(p.cargo_process("cargo-build"),
execs().with_status(0));
})
.file("src/foo.rs", r#"
pub fn foo() {}
"#);
- assert_that(p.cargo_process("cargo-compile"),
+ assert_that(p.cargo_process("cargo-build"),
execs().with_status(0));
let files = fs::readdir(&p.root().join("target")).assert();
let root = project.root();
let git_root = git_project.root();
- assert_that(project.cargo_process("cargo-compile"),
+ assert_that(project.cargo_process("cargo-build"),
execs()
.with_stdout(format!("{} git repository `file:{}`\n\
{} dep1 v0.5.0 (file:{})\n\
.file("src/parent.rs",
main_file(r#""{}", dep1::hello()"#, ["dep1"]).as_slice());
- p.cargo_process("cargo-compile")
+ p.cargo_process("cargo-build")
.exec_with_output()
.assert();
main_file(r#""{}", bar::bar()"#, ["bar"]).as_slice());
// First time around we should compile both foo and bar
- assert_that(p.cargo_process("cargo-compile"),
+ assert_that(p.cargo_process("cargo-build"),
execs().with_stdout(format!("{} git repository `file:{}`\n\
{} bar v0.5.0 (file:{})\n\
{} foo v0.5.0 (file:{})\n",
COMPILING, p.root().display())));
// Don't recompile the second time
- assert_that(p.process("cargo-compile"),
+ assert_that(p.process("cargo-build"),
execs().with_stdout(format!("{} bar v0.5.0 (file:{})\n\
{} foo v0.5.0 (file:{})\n",
FRESH, git_project.root().display(),
pub fn bar() { println!("hello!"); }
"#).assert();
- assert_that(p.process("cargo-compile"),
+ assert_that(p.process("cargo-build"),
execs().with_stdout(format!("{} bar v0.5.0 (file:{})\n\
{} foo v0.5.0 (file:{})\n",
FRESH, git_project.root().display(),
FRESH, p.root().display())));
- assert_that(p.process("cargo-compile").arg("-u"),
+ assert_that(p.process("cargo-build").arg("-u"),
execs().with_stdout(format!("{} git repository `file:{}`\n\
{} bar v0.5.0 (file:{})\n\
{} foo v0.5.0 (file:{})\n",
git_project.process("git").args(["commit", "-m", "test"]).exec_with_output()
.assert();
- assert_that(p.process("cargo-compile").arg("-u"),
+ assert_that(p.process("cargo-build").arg("-u"),
execs().with_stdout(format!("{} git repository `file:{}`\n\
{} bar v0.5.0 (file:{})\n\
{} foo v0.5.0 (file:{})\n",
}
"#);
- p.cargo_process("cargo-compile")
+ p.cargo_process("cargo-build")
.exec_with_output()
.assert();
pub fn bar() {}
"#);
// First time around we should compile both foo and bar
- assert_that(p.cargo_process("cargo-compile"),
+ assert_that(p.cargo_process("cargo-build"),
execs().with_stdout(format!("{} bar v0.5.0 (file:{})\n\
{} foo v0.5.0 (file:{})\n",
COMPILING, bar.display(),
COMPILING, p.root().display())));
// This time we shouldn't compile bar
- assert_that(p.process("cargo-compile"),
+ assert_that(p.process("cargo-build"),
execs().with_stdout(format!("{} bar v0.5.0 (file:{})\n\
{} foo v0.5.0 (file:{})\n",
FRESH, bar.display(),
FRESH, p.root().display())));
p.build(); // rebuild the files (rewriting them in the process)
- assert_that(p.process("cargo-compile"),
+ assert_that(p.process("cargo-build"),
execs().with_stdout(format!("{} bar v0.5.0 (file:{})\n\
{} foo v0.5.0 (file:{})\n",
COMPILING, bar.display(),
.file("baz/src/baz.rs", r#"
pub fn baz() {}
"#);
- assert_that(p.cargo_process("cargo-compile"),
+ assert_that(p.cargo_process("cargo-build"),
execs().with_stdout(format!("{} baz v0.5.0 (file:{})\n\
{} bar v0.5.0 (file:{})\n\
{} foo v0.5.0 (file:{})\n",
COMPILING, baz.display(),
COMPILING, bar.display(),
COMPILING, p.root().display())));
- assert_that(p.process("cargo-compile"),
+ assert_that(p.process("cargo-build"),
execs().with_stdout(format!("{} baz v0.5.0 (file:{})\n\
{} bar v0.5.0 (file:{})\n\
{} foo v0.5.0 (file:{})\n",
File::create(&p.root().join("baz/src/baz.rs")).write_str(r#"
pub fn baz() { println!("hello!"); }
"#).assert();
- assert_that(p.process("cargo-compile"),
+ assert_that(p.process("cargo-build"),
execs().with_stdout(format!("{} baz v0.5.0 (file:{})\n\
{} bar v0.5.0 (file:{})\n\
{} foo v0.5.0 (file:{})\n",
extern crate baz;
pub fn bar() { println!("hello!"); baz::baz(); }
"#).assert();
- assert_that(p.process("cargo-compile"),
+ assert_that(p.process("cargo-build"),
execs().with_stdout(format!("{} baz v0.5.0 (file:{})\n\
{} bar v0.5.0 (file:{})\n\
{} foo v0.5.0 (file:{})\n",
.file("baz/src/baz.rs", r#"
pub fn baz() {}
"#);
- assert_that(p.cargo_process("cargo-compile"),
+ assert_that(p.cargo_process("cargo-build"),
execs().with_stdout(format!("{} baz v0.5.0 (file:{})\n\
{} bar v0.5.0 (file:{})\n\
{} foo v0.5.0 (file:{})\n",
COMPILING, baz.display(),
COMPILING, bar.display(),
COMPILING, p.root().display())));
- assert_that(p.process("cargo-compile"),
+ assert_that(p.process("cargo-build"),
execs().with_stdout(format!("{} baz v0.5.0 (file:{})\n\
{} bar v0.5.0 (file:{})\n\
{} foo v0.5.0 (file:{})\n",